import React from 'react'

// 怎么就死了？ ...
class Auto extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            key: '',
            list: [],
        }
    }

    onKeyChange = (e) => {
        let value = e.target.value
        this.setState({
            key: value,
        })
        fetch('mock://search').then((res) => {
            this.setState({
                list: res,
            })
        }).catch((err) => {
            alert(err)
        })
    }

    render () {
        let listEls = this.state.list.map(item => {
            return <li>{item}</li>
        })
        return (
            <div>
                <input onChange={this.onKeyChange}/>
                <span>{this.state.key}</span>
                <ul>
                    {listEls}
                </ul>
            </div>
        )
    }
}
